<template>
  <div>
    <h1>食谱管理</h1>
    <div>
      <el-button type="primary" @click="contentadd()">食谱方案添加</el-button>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="ID" width="180"></el-table-column>
      <el-table-column
        prop="content"
        label="介绍"
        width="180"
      ></el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleClick(scope.row)">
            删除
          </el-button>
          <el-button type="text" size="small" @click="casecontent(scope.row)">查看改善方案</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-pagination
        :current-page="current"
        :page-sizes="[1, 2, 3, 5]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totel"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
    <div>
      <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
        <el-form :model="tbCaseContent">
          <el-form-item label="食谱方案名称" :label-width="formLabelWidth">
            <el-input
              v-model="tbCaseContent.content"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addcase()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import { casecontentadd, caseContentDelete, commodityAdmin, commodityAdminb, sppage } from "@/api/case";

  export default {
    name: 'CommodityAdminb',
    data() {
      return {
        tableData: [],
        dialogFormVisible: false,
        formLabelWidth: '120px',
        tbCaseContent: {
          id: '',
          pid: '',
          content: '',
          typeid: '2',
          caseid: '',
          starttime: '',
          updatetime: '',
          deleted: '',
        },
        tbCaseContentpage: {
          current: 1,
          pagesize: 5,
        },
        totel: 0,
        tbCaseContentd:{
          id: '',
        }
      }
    },
    mounted() {
      console.log('case.....')
      this.sppage()
    },
    methods: {
      list1() {
        commodityAdminb().then((res) => {
          this.tableData = res.data
        })
      },
      contentadd() {
        this.dialogFormVisible = true
      },
      addcase() {
        casecontentadd(this.tbCaseContent).then((res) => {
          this.sppage()
          console.log(res)
          this.dialogFormVisible = false
        })
      },
      sppage() {
        sppage(this.tbCaseContentpage).then((res) => {
          this.tableData = res.data.records
          this.totel = res.data.total
          console.log(res)
        })
      },
      handleSizeChange(val) {
        this.tbCaseContentpage.pagesize = val
        this.sppage()
        console.log(`每页 ${val} 条`)
      },
      handleCurrentChange(val) {
        this.tbCaseContentpage.current = val
        this.sppage()
        console.log(`当前页: ${val}`)
      },
      handleClick(row) {
        this.tbCaseContentd.id = row.id
        alert(this.tbCaseContentd.id)
        caseContentDelete(this.tbCaseContentd).then((res) => {
          this.sppage()
          console.log(res)
        })
      },
    },
  }
</script>

<style scoped></style>
